<script setup lang="ts">
import { getCarPayListAPI } from '@/apis/carPay';
import type { CarPayItemType, CarPayDataParams } from '@/types/carPay';
import { ref } from 'vue';

// 参数
const carPayParams = ref<CarPayDataParams>({
  carNumber: undefined,
  paymentStatus: undefined,
  page: 1,
  pageSize: 5
})

// 获取数据
const carPayList = ref<CarPayItemType[]>([])
const total = ref<number>(0)

const getCarPayData = async () => {
  const res = await getCarPayListAPI(carPayParams.value)
  total.value = res.data.total
  carPayList.value = res.data.rows
}
getCarPayData()

// 缴费方式
const getPaymentMethod = (type: string) => {
  let content = '--'
  if (type === 'Alipay') {
    content = '支付宝'
  } else if (type === 'WeChat') {
    content = '微信'
  } else if (type === 'Cash') {
    content = '线下'
  }
  return content
}

</script>

<template>
  <div class="card-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <span class="search-label">车牌号码：</span>
      <el-input @clear="getCarPayData()" v-model="carPayParams.carNumber" placeholder="请输入车牌号码" clearable class="search-main" />
      <span class="search-label">缴纳状态：</span>
      <el-select @clear="getCarPayData()" v-model="carPayParams.paymentStatus" placeholder="未选择" clearable style="width: 240px">
        <el-option label="待缉拿" value="0" />
        <el-option label="已缉拿" value="1" />
      </el-select>
      <el-button type="primary" class="search-btn" @click="getCarPayData()">查询</el-button>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table style="width: 100%" :data="carPayList">
        <el-table-column type="index" label="序号" width="60" align="center" />
        <el-table-column label="车牌号码" prop="carNumber" />
        <el-table-column label="收费类型">
          <template #default="scope">
              {{ scope.row.chargeType === 'card' ? '月卡' : '临时停车' }}
          </template>
        </el-table-column>
        <el-table-column label="停车总时长" prop="parkingTime" />
        <el-table-column label="缉拿费用" prop="actualCharge">
          <template #default="scope">
            {{ scope.row.actualCharge ? scope.row.actualCharge : '--' }}
          </template>
        </el-table-column>
        <el-table-column label="缉拿状态" prop="paymentStatus">
          <template #default="scope">
            {{ scope.row.paymentStatus === 1 ? '已缴纳' : '未缴纳' }}
          </template>
        </el-table-column>
        <el-table-column label="缉拿方式" prop="paymentMethod">
          <template #default="scope">
            {{ getPaymentMethod(scope.row.paymentMethod) }}
          </template>
        </el-table-column>
        <el-table-column label="缉拿时间">
          <template #default="scope">
            {{ scope.row.paymentTime ? scope.row.paymentTime : '--' }}
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="page-container">
      <el-pagination 
        layout="total, sizes, prev, pager, next"
        :total="total"
        :page-sizes="[2,5,10,20]"
        v-model:current-page="carPayParams.page"
        v-model:page-size="carPayParams.pageSize"
        @change="getCarPayData()"
      />
    </div>
  </div>
</template>

<style lang="scss" scoped>
.card-container {
  padding: 20px;
  background-color: #fff;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, .9);
  padding: 10px 0 30px;

  .search-main {
    width: 220px;
    margin-right: 10px;
  }

  .search-btn {
    margin-left: 20px;
  }
}

.page-container {
  padding: 4px 0px;
  text-align: right;
}

.form-container {
  padding: 0px 80px;
}
</style>
